﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace UCWebpart
{
    public partial class MeetingroomResourceControl : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        protected void GridView1_PageIndexChanged(object sender, EventArgs e)
        {

        }

        protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {

        }

        protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "Insert" && Page.IsValid)
            {
                TextBox mtr_resId = (TextBox)GridView1.FooterRow.FindControl("mtr_res_id");
                DropDownList mtr = (DropDownList)GridView1.FooterRow.FindControl("mtrId_DDL");
                DropDownList res = (DropDownList)GridView1.FooterRow.FindControl("resId_DDL");
                
                using (var mtr_resEn = new meetingroomManagementEntities()) {

                    MTR_bas_MeetingroomResources mtr_res = new MTR_bas_MeetingroomResources();

                    //mtr_res.mtr_res_id = mtr_resId.Text.Trim() == string.Empty ? 0 : Convert.ToInt32(mtr_resId.Text);

                    //mtr_res.mtr_res_id = Convert.ToInt32(mtr_resId.Text);
                    mtr_res.mtrId = Convert.ToInt32(mtr.SelectedValue);
                    mtr_res.resId = Convert.ToInt32(res.SelectedValue);
                    //跟据mtr.Text的内容，取出下拉框内容对应的编号  放到map中？？

                    //mtr_res.mtrId = mtr.Text;

                    mtr_resEn.MTR_bas_MeetingroomResources.Add(mtr_res);
                    mtr_resEn.SaveChanges();
                    GridView1.DataBind();

                    GridView1.EditIndex = -1;
                    //GridView1.DataSource=mtrEn.MTR_bas_Meetingroom;
                    GridView1.DataBind();
                  

                }
            
            }

        }
    }
}